﻿using System;
using System.Linq;
using System.Text.RegularExpressions;
using ReAnimation.Domain.Policies.Interfaces;
using ReAnimation.Domain.Policies.Interfaces.ErrorEnums;
using ReAnimation.Helpers.Common;

namespace ReAnimation.Domain.Policies
{
    public class MoleculePolicy : IMoleculePolicy
    {
        //todo: move policies to another project, need to check name duplicates
        #region IMoleculePolicy Members

        public ValidationResult<IncorrectMoleculeNameErrors> CheckName(string name)
        {
            if (String.IsNullOrEmpty(name))
                return
                    ValidationResult<IncorrectMoleculeNameErrors>.FailValidation(IncorrectMoleculeNameErrors.EmptyString);

            var regex = new Regex(@"^(\w|\ )*$");
            if (!regex.IsMatch(name))
                return
                    ValidationResult<IncorrectMoleculeNameErrors>.FailValidation(IncorrectMoleculeNameErrors.NonLatinCharacters);

            return ValidationResult<IncorrectMoleculeNameErrors>.SuccessValidation();
        }
        #endregion
    }
}